package chapter2.No2_2_synchronized同步语句块.g将任意对象作为对象监视器.demo2;

/**
 * Created by Administrator on 2016/11/12.
 */
public class ServiceClass {

    String anyObj = new String();

    public void methodA() {
        synchronized (anyObj) {
            try {
                System.out.println("线程："+Thread.currentThread().getName()+" 进入对象监控器的A方法");
                Thread.sleep(1200);
                System.out.println("线程："+Thread.currentThread().getName()+" 退出对象监控器的A方法");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void methodBsync() {
        System.out.println("线程："+Thread.currentThread().getName()+"进入B同步方法");
    }

}
